package com.ustc.py.learn.controller;


import com.mysql.cj.util.StringUtils;
import com.ustc.py.learn.constant.KnowledgeTypeEnum;
import com.ustc.py.learn.entity.KnowledgeVo;
import com.ustc.py.learn.service.KnowledgeService;
import com.ustc.py.learn.service.StudentProgressService;
import com.ustc.py.storage.LoginUserLocalStorage;
import com.ustc.py.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@ResponseBody
@RequestMapping("/learn/algorithm")
public class LearnAlgorithmController {

    @Autowired
    private KnowledgeService knowledgeService;

    @Autowired
    private StudentProgressService studentProgressService;

    /**
     * 获取所有算法知识的列表
     * @return
     */
    @GetMapping("/list")
    public R getAlgorithmKnowledgeList() {
        List<KnowledgeVo> algorithmKnowledgeMenu =
                knowledgeService.getKnowledgeMenuList(KnowledgeTypeEnum.ALGORITHM.getTypeId());
        return R.ok().put("data", algorithmKnowledgeMenu);
    }

    /**
     * 根据主键id 查某算法知识具体详情
     * @param knowledgeId
     * @return
     */
    @GetMapping("/{knowledgeId}")
    public R getAlgorithmKnowledge(@PathVariable("knowledgeId") int knowledgeId) {
        KnowledgeVo knowledgeVo = knowledgeService.getKnowledge(knowledgeId);
        return R.ok().put("data", knowledgeVo);
    }


    /**TODO：
     * 标记某个算法章节知识点状态是已经完成学习
     * @param chapterId
     * @return
     */
    @PostMapping("/chapter/{chapterId}")
    public R setLearningProgress(@PathVariable("chapterId") int chapterId) {
        Long userId = LoginUserLocalStorage.getCurrentLoginUserId();
        studentProgressService.setAlgorithmLearningProgress(userId, chapterId);
        return R.ok();
    }
}
